package com.supermap.disaster.dao;

import com.supermap.disaster.entity.DisasterComment;
import com.supermap.disaster.entity.DisasterType;
import com.supermap.disaster.entity.Disasterpraise;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @author lxs
 * @Title:灾害数据访问层
 * @Description:
 * @date 2018/3/1  15:15
 */
@Mapper
public interface DisasterTypeDao {
    /**所有的灾害信息
     * 查询
     * @return
     */
    @Select("select * from t_disastertype ")
    List<DisasterType> getAllDisasterType();

    /**
     * 根据灾情ID得到所有的点赞数
     * @param disasterId
     * @return
     */
    @Select("select COUNT(*) from t_disasterpraise where disasterId=#{disasterId}")
    int getDisasterPraiseCount(@Param("disasterId")int disasterId);

    /**
     * 根据灾情ID和userId判断该灾情是否被该user点过赞
     * @param userId
     * @param disasterId
     * @return
     */
    @Select("select isPraise from   t_disasterpraise where userId=#{userId} and disasterId=#{disasterId}")
    String  getDisasterPraise(@Param("userId")int userId,@Param("disasterId")int disasterId);

    /**
     *添加点赞
     * @param disasterpraise
     * @return
     */
    @Insert("Insert into t_disasterpraise(disasterId,isPraise,userId) "+"values(#{disasterpraise.disasterId},#{disasterpraise.isPraise},#{disasterpraise.userId}"+")")
    int addDisasterPraise(@Param("disasterpraise")Disasterpraise disasterpraise);

    @Delete("delete from t_disasterpraise where  userId=#{userId} and disasterId=#{disasterId}")
    int DelDisById(@Param("userId")int userId,@Param("disasterId")int disasterId);

    /**
     * 根据灾害ID 得到对应下的所有评论
     * @param disasterId
     * @return
     */
    @Select("select t1.*,t2.username from t_disastercomment t1 inner JOIN t_user t2 on t1.userId=t2.id  where t1.disasterId=#{disasterId}")
    List<DisasterComment> getAllDisasterCommentByagrInfoId(@Param("disasterId")int disasterId);

    /**
     * 添加灾害评论
     * @param disasterComment
     * @return
     */
    @Insert("Insert into t_disastercomment(disasterId,comment,parentId,userId) "+"values(#{disasterComment.disasterId},#{disasterComment.comment},#{disasterComment.parentId},#{disasterComment.userId}"+")")
    int addDisasterComment(@Param("disasterComment")DisasterComment disasterComment);

    /**
     * 添加 默认为未阅读的评论数据
     * @param userid
     * @param typeid
     * @param type
     * @param comment
     * @param state
     * @return
     */
    @Insert("Insert into t_newmessage(userid,typeid,type,comment,state,uid) "
            +"values(#{userid},#{typeid},#{type},#{comment},#{state},#{uid})")
    int addNewMessage(@Param("userid")int userid, @Param("typeid")int typeid, @Param("type")int type, @Param("comment")String comment, @Param("state")int state, @Param("uid")String uid);
}
